import { Button, Checkbox, Form, Input, message } from "antd";
import { useNavigate, useRevalidator } from "react-router-dom";
import "./index.scss";
import { login } from "../../apis/loginApi";
const Login = () => {
  const navigate = useNavigate();
  const revalidator = useRevalidator();
  interface data {
    username: string;
    password: string;
    type: string;
  }
  const onFinish = (values: data) => {
    /* login(values).then((res: { [propName: string]: any }) => {
      console.log(res);
      if (res.error == 0) {
        sessionStorage.setItem("token", res.token);
        sessionStorage.setItem("user", JSON.stringify(res.data[0]));
        sessionStorage.setItem("power", JSON.stringify(res.power));
        message.success("登录成功");
        revalidator.revalidate();
        navigate("/home");
      }
    }); */
    navigate('/home')
  };

  const onFinishFailed = (errorInfo: any) => {
    console.log("Failed", errorInfo);
  };
  return (
    <div className="login">
      <Form
        className="form"
        name="basic"
        labelCol={{ span: 6 }}
        wrapperCol={{ span: 16 }}
        initialValues={{ remember: true }}
        onFinish={onFinish}
        onFinishFailed={onFinishFailed}
        autoComplete="off"
      >
        <Form.Item
          label="账号"
          name="username"
          rules={[{ required: true, message: "请输入账号!" }]}
        >
          <Input />
        </Form.Item>

        <Form.Item
          label="密码"
          name="password"
          rules={[{ required: true, message: "请输入密码!" }]}
        >
          <Input.Password />
        </Form.Item>

        <Form.Item
          name="remember"
          valuePropName="checked"
          wrapperCol={{ offset: 8, span: 16 }}
        >
          <Checkbox>记住我</Checkbox>
        </Form.Item>

        <Form.Item wrapperCol={{ offset: 11, span: 16 }}>
          <Button type="primary" htmlType="submit">
            登录
          </Button>
        </Form.Item>
      </Form>
    </div>
  );
};
export default Login;
